package com.movitech.wechat.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;

public class FileUtil
{
  public static void download(String url)
  {
    HttpClient client = new HttpClient();
    GetMethod get = new GetMethod(url);
    try {
      client.executeMethod(get);
      String name = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
      File storeFile = new File("C:/" + name + ".jpg");
      FileOutputStream fileOutputStream = new FileOutputStream(storeFile);
      FileOutputStream output = fileOutputStream;
      output.write(get.getResponseBody());
      output.close();
    }
    catch (HttpException e) {
      e.printStackTrace();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }
}